"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _jsxRuntime = require("react/jsx-runtime");

var _icons = require("@ant-design/icons");

var _antdV = require("antd-v4");

var _react = _interopRequireWildcard(require("react"));

var _createField = require("../../BaseForm/createField");

/**
 * 拖动上传组件
 *
 * @param
 */
var BaseProFormUploadDragger = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
  var fieldProps = _ref.fieldProps,
      _ref$title = _ref.title,
      title = _ref$title === void 0 ? '单击或拖动文件到此区域进行上传' : _ref$title,
      _ref$icon = _ref.icon,
      icon = _ref$icon === void 0 ? (0, _jsxRuntime.jsx)(_icons.InboxOutlined, {}) : _ref$icon,
      _ref$description = _ref.description,
      description = _ref$description === void 0 ? '支持单次或批量上传' : _ref$description,
      action = _ref.action,
      accept = _ref.accept,
      _onChange = _ref.onChange,
      value = _ref.value,
      children = _ref.children,
      max = _ref.max,
      proFieldProps = _ref.proFieldProps;
  var context = (0, _react.useContext)(_antdV.ConfigProvider.ConfigContext);
  var baseClassName = context.getPrefixCls('upload'); // 如果配置了 max ，并且 超过了文件列表的大小，就不展示按钮

  var showUploadButton = (max === undefined || !value || (value === null || value === void 0 ? void 0 : value.length) < max) && (proFieldProps === null || proFieldProps === void 0 ? void 0 : proFieldProps.mode) !== 'read' && (proFieldProps === null || proFieldProps === void 0 ? void 0 : proFieldProps.readonly) !== true;
  return (0, _jsxRuntime.jsxs)(_antdV.Upload.Dragger // @ts-ignore
  , (0, _objectSpread2.default)((0, _objectSpread2.default)({
    // @ts-ignore
    ref: ref,
    name: "files",
    action: action,
    accept: accept,
    fileList: value
  }, fieldProps), {}, {
    onChange: function onChange(info) {
      _onChange === null || _onChange === void 0 ? void 0 : _onChange(info);

      if (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.onChange) {
        fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.onChange(info);
      }
    },
    style: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.style), {}, {
      display: !showUploadButton ? 'none' : undefined
    }),
    children: [(0, _jsxRuntime.jsx)("p", {
      className: "".concat(baseClassName, "-drag-icon"),
      children: icon
    }), (0, _jsxRuntime.jsx)("p", {
      className: "".concat(baseClassName, "-text"),
      children: title
    }), (0, _jsxRuntime.jsx)("p", {
      className: "".concat(baseClassName, "-hint"),
      children: description
    }), children ? (0, _jsxRuntime.jsx)("div", {
      className: "".concat(baseClassName, "-extra"),
      style: {
        padding: 16
      },
      children: children
    }) : null]
  }));
});

var ProFormUploadDragger = (0, _createField.createField)(BaseProFormUploadDragger, {
  getValueFromEvent: function getValueFromEvent(value) {
    return value.fileList;
  }
});
var _default = ProFormUploadDragger;
exports.default = _default;